草庐IT

javascript setTimeout调用错误

全部标签

javascript - 错误 "Unhandled ' 错误'事件“运行 yo 生成器后

我正在尝试使用generatos的生成器,generator-generator,但遇到错误。henrique@liberato:~/Documents$yogenerator?Yourgeneratorname(generator-documents)events.js:154thrower;//Unhandled'error'event^TypeError:this.env.adapter.prompt(...).thenisnotafunctionatBase.prompt(/home/henrique/.nvm/versions/node/v5.8.0/lib/node_mod

javascript - Angular 2 HTTP获取处理404错误

我有一个提供空json的服务,但我收到了这些错误。如果我使用https://jsonplaceholder.typicode.com/posts/6然后就可以了。我怎样才能以正确的方式处理这些错误?服务:constructor(privatehttp:Http){}fetchData(){returnthis.http.get('https://jsonplaceholder.typicode.com/psts/6').map((res)=>res.json()).subscribe((data)=>console.log(data));}错误: 最佳答案

javascript - 为返回 promise 数组的 Array.map 调用添加毫秒延迟

我的需求很简单。我想将对sendEmail的调用延迟100毫秒。电子邮件服务提供商允许每秒最多发送10封电子邮件。但是请注意,虽然.map是同步的,但它会立即返回一个Promise。我试过setTimeout没有用,比如setTimeout(()=>resolve(x),100)和setTimeout(()=>{returnnewPromise....},100)。想法?constpromises=userEmailArray.map((userEmail)=>{returnnewPromise((resolve,reject)=>{....mailer.sendEmail(userE

javascript - Prefer destructuring es-lint错误

我有这个功能:constcalculateTotal=(items)=>{returnitems.reduce((totalPrice,basketItem)=>{constprice=basketItem.product.price;constquantity=basketItem.quantity;consttotal=price*quantity;returntotalPrice+total;},0);};如何使用ES6+解构来解决这个问题?我知道我需要类似的东西(第4行):const{basketItem:数量}=数量;但是我无法让第3行工作 最佳答

javascript - 为什么两个函数调用的括号之间的换行符不被视为 js 中的两个语句?

为什么在js上做这种烂设计?这样设计自动插入分号是不是有什么特别的原因?这是我的代码,它不适用于js中的chrome:(function(){console.log("abc");})()(function(){console.log("123");})();这里是错误:UncaughtTypeError:(intermediatevalue)(...)isnotafunction我知道这段代码的正确版本是:(function(){console.log("abc");})();(function(){console.log("123");})();我就是想知道为什么js语法设计的这么

javascript - 使用 Ajax 调用从函数返回值

这个问题在这里已经有了答案:HowdoIreturntheresponsefromanasynchronouscall?(41个回答)关闭9年前。谁能告诉我如何返回status的值作为函数的返回值。functioncheckUser(){varrequest;varstatus=false;//createxmlhttprequestobjecthere[calledrequest]varstu_id=document.getElementById("stu_id").value;vardName=document.getElementById("dName").value;varfi

javascript - 从 AJAX 调用返回和显示数据的最佳实践

我在页面上设置了一些jquery/php交互。它向服务器提交一些数据并取回数据记录,然后将这些数据在页面上对齐以进行比较和可能的操作。我的问题是返回信息然后显示它的最佳做法是什么?返回JSON对象然后创建html与js一起显示数据?返回JSON对象然后将该数据放入已创建的页面数据的容器?从服务器返回纯html和只是把它放在页面上?昨晚我在脑海里翻来覆去,无法真正弄清楚是否有一种方法会因任何特定原因而变得更好。我不是js专家,所以不确定这些不同方法的优缺点和注意事项。 最佳答案 我认为最终取决于您的应用。纯HTML是最简单的,您只需就

javascript - 我的心智模型错了吗?如果使用 https 调用页面,则将使用 https 调用相对 css 路径

Ifyourpagegetscalledusinghttpsprotocol,anyrelativepathtoanexternalcsswillbecalledusinghttpsprotocolaswell.Areyoureallyneedtoencrypt/decryptcsscontents?:DHowever,ifyouuseabsolutepathreferringtoanexternalcss,youcanspecifytheprotocoltouse,generallyhttpratherthanhttps.MaybeIamwrong!请让我知道我的心智模型是否完全错误

javascript - jQuery 对 javascript 类方法的 AJAX 调用

我是jQuery工作流程的新手,我想设置一个使用内部方法发出AJAX请求的javascript类。当请求成功返回时,jQueryAJAX回调应该调用类本身拥有的方法。那是代码:functionIXClock(){this.m_intervalID=0;this.startClock=function(){this.m_intervalID=setInterval(this.tictac,500);}this.stopClock=function(){clearInterval(this.m_intervalID);}this.setClockTime=function(p_strTim

使用postman访问springboot项目,出现Unsupported Media Type 415错误以及 Field ‘userId‘ doesn‘t have a default value

使用postman访问springboot项目,出现UnsupportedMediaType415错误以及java.sql.SQLException:Field‘userId’doesn’thaveadefaultvalueidea控制台显示Resolved[org.springframework.web.HttpMediaTypeNotSupportedException:Contenttype‘multipart/form-data;boundary=--------------------------508983844580882655519308;charset=UTF-8’notsu